<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<shiro:lacksPermission name="gys:look">没有查询此模块权限。。。</shiro:lacksPermission>
<shiro:hasPermission name="gys:look">
    <!DOCTYPE HTML>
    <html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css"
              href="easyui/themes/bootstrap/easyui.css">
        <script type="text/javascript" src="easyui/jquery.min.js"></script>
        <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
        <script type="text/javascript" src="myjs/path.js"></script>
        <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="myjs/gongyingshang.js"></script>
        <script src="js/yangshi.js"></script>

    </head>
    <body class="easyui-layout">

    <div id="tb" style="height: auto">
        <shiro:hasPermission name="gys:create">
            <a href="javascript:void(0)" class="easyui-linkbutton"
               data-options="iconCls:'icon-add',plain:true" onclick="openWindow(1)">新增</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="gys:del">
            <a href="javascript:void(0)" class="easyui-linkbutton"
               data-options="iconCls:'icon-remove',plain:true" id="delt"
               onclick="shanchu()">删除</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="gys:update">
            <a href="javascript:void(0)" class="easyui-linkbutton"
               iconCls="icon-edit" plain="true" onclick="openWindow(2)">修改</a>
        </shiro:hasPermission>
        <input id="ss" class="easyui-searchbox" style="width:250px"
               data-options="searcher:qq,prompt:'请输入供应商关键词',menu:'#mm'">
        <a iconCls="icon-save" class="easyui-linkbutton" type="button" onclick="downExcel()">导出Excel</a>
        <div id="mm" style="width:120px">
            <div data-options="name:'-1'">全部</div>
            <div data-options="name:'0',iconCls:'icon-ok'">自产</div>
            <div data-options="name:'1',iconCls:'icon-no'">进货</div>
        </div>
        <script type="text/javascript">
            function qq(value, name) {
                //value是搜索框里的值,name是选择框里的值
                $("#dg").datagrid({
                    url: path + '/gongyingshang/list.do',
                    queryParams: {
                        leixing: name,
                        gname: value.trim()
                    }
                })
            }
        </script>

    </div>
    <table id="dg" class="easyui-datagrid">

    </table>
        <%--新增入口--%>
    <div id="addwindow" class="easyui-dialog"
         data-options="buttons:'#bb', modal:true,closed:true,collapsible:false,iconCls:'icon-save',minimizable:false,maximizable:false"
         style="padding: 30px;">
        <input id="id" type="hidden">
        <table>
            <tr>
                <td align="right">供应商名称：</td>
                <td align="left"><input id="gname" class="easyui-textbox" style="width:200px;"
                                        data-options="prompt:'请输入供应商名称'"><br><span style="font-size: 12px;color: red;"
                                                                                   id="gnametest"></span>
                </td>
            </tr>
            <tr>
                <td align="right">供应商类型：</td>
                <td><select id="leixing" class="easyui-combobox" style="width:200px;" data-options="editable:false">
                    <option value="0">自产</option>
                    <option value="1">进货</option>
                </select>
                </td>
            </tr>
            <tr>
                <td align="right">负责人：</td>
                <td><input id="person" class="easyui-textbox" style="width:200px;"
                           data-options="prompt:'请输入负责人'"><br>
                </td>
            </tr>
            <tr>
                <td align="right">联系方式：</td>
                <td><input id="phone" class="easyui-textbox" style="width:200px;"
                           data-options="prompt:'请输入联系方式'">
                </td>
            </tr>
            <tr>
                <td align="right">地址：</td>
                <td><input id="address" class="easyui-textbox" style="width:200px;height: 60px"
                           data-options="prompt:'请输入地址',multiline:true">
                </td>
            </tr>
        </table>
        <div id="bb">
            <button onclick="save()"
                    class="easyui-linkbutton" data-options="iconCls:'icon-save' ">保存
            </button>
            <button onclick="$('#addwindow').window('close')"
                    class="easyui-linkbutton" data-options="iconCls:'icon-no'">取消
            </button>
        </div>
    </div>
    </body>

    <script type="text/javascript">
        $('#gname').textbox({
            events: {
                blur: function () {
                    //由于获取是上一次的值 所有这里有this.value
                    var gname = this.value;
                    if (gname == "" || gname == null) {
                        $("#gnametest").text("*请输入供应商名称");
                        return;
                    }
                    var id = $('#id').val();
                    $.ajax({
                        url: path + '/gongyingshang/find/gname.do',
                        dataType: 'json',
                        type: 'POST',
                        data: {
                            gname: gname,
                            id: id
                        },
                        success: function (data) {
                            if (data.code == 400) {
                                $("#gnametest").text("*已存在该供应商")
                            } else {
                                $("#gnametest").text("");
                            }
                        }
                    })
                }
            }
        });


        $("#dg").datagrid({
            url: path + '/gongyingshang/list.do'
        });
        $("#dg").datagrid({
            method: 'GET',
            striped: true,
            rownumbers: false,
            singleSelect: true,
            toolbar: '#tb',
            checkbox: false,
            fit: true,
            striped: true,
            fitColumns: false,
            autoRowHeight: false,
            rownumbers: true,
            pagination: true,
            pageSize: 20,
            pageList: [20, 30, 50],
            nowrap: true,
            loadMsg: '加载中,请稍后......',
            columns: [[{
                field: 'id',
                title: '类别',
                width: 80,
                hidden: true
            }, {
                field: 'gname',
                title: '供应商名称',
                width: 150,
                align: 'center'
            }, {
                field: 'leixing',
                title: '供应商类型',
                width: 80,
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 0) {
                        return '自产'
                    } else if (value == 1) {
                        return '进货'
                    }
                }
            }, {
                field: 'person',
                title: '负责人',
                width: 80,
                align: 'center'
            }, {
                field: 'phone',
                title: '联系方式',
                width: 150,
                align: 'center'
            }, {
                field: 'address',
                title: '地址',
                width: 150,
                align: 'center'
            }]],
            //loadFilter : function(responseData) {
            //	return responseData.data;
            //},
            onBeforeLoad: function (param) {
            },
            onLoadSuccess: function (data) {
                $("#ss").next().find("input").eq(0).focus();
            },
            onLoadError: function () {
                //	console.debug('not ok')
            }
        });

    </script>
</shiro:hasPermission>
